// https://www.acwing.com/problem/content/description/915/

#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main() {
    int n, t;
    scanf("%d", &n);
    priority_queue<int, vector<int>, greater<int>> PQ;
    for (int i = 0; i < n; i++) {
        scanf("%d", &t);
        PQ.push(t);
    }

    long long ans = 0;
    int w = 0;
    while (!PQ.empty()) {
        ans += w;
        w += PQ.top();
        PQ.pop();
    }

    printf("%lld\n", ans);
    return 0;
}